﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using ERP_RORZE_ORDER.BizLogic;
using ERP_RORZE_ORDER.Common;
using ERP_RORZE_ORDER.Common.ValueObject;
using ERP_RORZE_ORDER.OrderObject.Forms;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_SYSTEM;
using BaseDAO = ERP_RORZE_TOOL.DBAccess.BaseDAO;
using Utilities = ERP_RORZE_TOOL.Common.Utilities;

namespace ERP_RORZE_ORDER.OrderObject.UserControls
{
    public partial class ucProduct : DevExpress.XtraEditors.XtraUserControl
    {
        private int index = 0;
        public int _action = 1;
        DXPopupMenu menu;
        ProductHelper helper = new ProductHelper(new Product());
        private LogUtils log;

        #region Handle methods
        public ucProduct()
        {
            InitializeComponent();
            InitPopupMenu();
            log = new LogUtils();

            BindDatatoGrid();
            this.dropbtExport.DropDownControl = menu;
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            DeleteRows();
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            EditRow();
        }

        private void btAddNew_Click(object sender, EventArgs e)
        {
            AddNew();
        }

        private void btRefresh_Click(object sender, EventArgs e)
        {
            BindDatatoGrid();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            ImportData();
        }

        private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
        {
            if (gridView1.RowCount != 0)
                return;

            StringFormat drawFormat = new StringFormat();

            drawFormat.Alignment = drawFormat.LineAlignment = StringAlignment.Center;

            e.Graphics.DrawString("No items exist in this view", e.Appearance.Font, SystemBrushes.ControlDark, new RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), drawFormat);

        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            var gridView = (GridView)sender;
            var point = gridView.GridControl.PointToClient(Control.MousePosition);

            DoDoubleClick(gridView, point);
        }

        private void addNewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddNew();
        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditRow();
        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DeleteRows();
        }

        private void gridControl1_ProcessGridKey(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                DeleteRows();
            }
        }
        #endregion

        #region Private methods
        public void BindDatatoGrid()
        {
            ProductHelper helper = new ProductHelper(new Product());
            gridControl1.DataSource = helper.GetAll();
            //gridView1.BestFitColumns();
            Utilities.GridUtil.SelectRow(gridView1, index, _action);
        }

        private void DoDoubleClick(GridView v, Point p)
        {
            _action = 1;
            index = gridView1.FocusedRowHandle;
            var info = v.CalcHitInfo(p);
            if (info.InRow || info.InRowCell)
            {
                frm_ProductEdit fr = new frm_ProductEdit(this);
                if (!Utilities.FormUtil.IsFormOpen(fr))
                {
                    var row = new DataRow[gridView1.SelectedRowsCount];
                    row[0] = gridView1.GetDataRow(gridView1.GetSelectedRows()[0]);

                    string productId = row[0][OrderConstants.Entities.Product.FieldName.ProductID].ToString();
                    helper.ValueObject.ProductID = productId;
                    helper.LoadOne();

                    fr.ProductID = helper.ValueObject.ProductID;
                    fr.ProductName = helper.ValueObject.ProductName;
                    fr.EnglishName = helper.ValueObject.EnglishName;
                    fr.VietName = helper.ValueObject.VietName;
                    fr.JapanName = helper.ValueObject.JapanName;
                    fr.Size = helper.ValueObject.Size;
                    fr.MakerID = helper.ValueObject.MakerID;
                    fr.ProductGroupID = helper.ValueObject.ProductGroupID;
                    fr.SupplierID = helper.ValueObject.SupplierID;
                    fr.KindID = helper.ValueObject.KindID;
                    fr.UnitID = helper.ValueObject.UnitID;
                    fr.Price = helper.ValueObject.Price;
                    fr.CurrencyID = helper.ValueObject.CurrencyID;
                    fr.PurposeID = helper.ValueObject.PurposeID;

                    fr.StartPosition = FormStartPosition.CenterScreen;
                    fr.Show();
                }
            }
        }

        private void DeleteRows()
        {
            if (gridView1.SelectedRowsCount > 0)
            {
                var row = new DataRow[gridView1.SelectedRowsCount];
                var productId = new string[gridView1.SelectedRowsCount];

                for (int i = 0; i < gridView1.SelectedRowsCount; i++)
                {
                    row[i] = gridView1.GetDataRow(gridView1.GetSelectedRows()[i]);
                    productId[i] = row[i][OrderConstants.Entities.Product.FieldName.ProductID].ToString();
                }


                if (MessageBox.Show(OrderConstants.Message.DeleteQuestion, OrderConstants.Form.MessageBox.Warning,
                                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    ProductHelper helper = new ProductHelper(new Product());
                    for (int i = 0; i < productId.Length; i++)
                    {
                        helper.ValueObject.ProductID = productId[i];
                        if (helper.Delete() > 0)
                        {

                            //write Log
                            log.Table = LogConstant.Table.F2Order.Product;
                            log.Task = LogConstant.Task.Delete;
                            log.Description = "ProductID: " + helper.ValueObject.ProductID + "; ProductName: " + row[i][OrderConstants.Entities.Product.FieldName.ProductName];
                            log.WriteLog();

                            _action = 2;
                        }
                        else
                        {
                            MessageBox.Show(OrderConstants.Message.DeleteFailed, OrderConstants.Form.MessageBox.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    BindDatatoGrid();


                }
            }
            else
            {
                MessageBox.Show(OrderConstants.Message.TableIsNull, OrderConstants.Form.MessageBox.Message, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }

        private void EditRow()
        {

            if (gridView1.SelectedRowsCount > 0)
            {
                frm_ProductEdit fr = new frm_ProductEdit(this);
                if (!Utilities.FormUtil.IsFormOpen(fr))
                {


                    var row = new DataRow[gridView1.SelectedRowsCount];
                    row[0] = gridView1.GetDataRow(gridView1.GetSelectedRows()[0]);

                    index = gridView1.FocusedRowHandle;
                    _action = 1;

                    string productId = row[0][OrderConstants.Entities.Product.FieldName.ProductID].ToString();
                    helper.ValueObject.ProductID = productId;
                    helper.LoadOne();

                    fr.ProductID = helper.ValueObject.ProductID;
                    fr.ProductName = helper.ValueObject.ProductName;
                    fr.EnglishName = helper.ValueObject.EnglishName;
                    fr.VietName = helper.ValueObject.VietName;
                    fr.JapanName = helper.ValueObject.JapanName;
                    fr.Size = helper.ValueObject.Size;
                    fr.MakerID = helper.ValueObject.MakerID;
                    fr.ProductGroupID = helper.ValueObject.ProductGroupID;
                    fr.SupplierID = helper.ValueObject.SupplierID;
                    fr.KindID = helper.ValueObject.KindID;
                    fr.UnitID = helper.ValueObject.UnitID;
                    fr.Price = helper.ValueObject.Price;
                    fr.CurrencyID = helper.ValueObject.CurrencyID;
                    fr.PurposeID = helper.ValueObject.PurposeID;

                    fr.StartPosition = FormStartPosition.CenterScreen;
                    fr.Show();
                }
            }
            else
            {
                MessageBox.Show(OrderConstants.Message.TableIsNull, OrderConstants.Form.MessageBox.Message, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }

        private void AddNew()
        {
            Cursor.Current = Cursors.WaitCursor;
            Form fr = new frm_ProductAdd(this);
            fr.StartPosition = FormStartPosition.CenterScreen;

            if (!Utilities.FormUtil.IsFormOpen(fr))
            {
                fr.Show();
            }
            else
            {
                //fr.WindowState = FormWindowState.Normal;

                //fr.BringToFront();
                //fr.TopMost = true;
                //fr.Activate();
            }

            Cursor.Current = Cursors.Default;

        }

        private void ImportData()
        {
            INISettings mySetting = new INISettings();
            SqlConnection myConnection = new SqlConnection(mySetting.SQLConnectionString);

            int countOk = 0;
            int countDup = 0;
            int countErr = 0;

            List<Utilities.ListItem> listDup = new List<Utilities.ListItem>();
            List<Utilities.ListItem> listErr = new List<Utilities.ListItem>();
            FileDialog importFile = new OpenFileDialog();
            importFile.Filter = "Excel 2007-2013|*.xlsx|Excel 97-2003 (*.xls)|*.xls";
            if (importFile.ShowDialog() == DialogResult.OK)
            {
                OleDbConnection excelConnection = null;
                try
                {
                    Control parent = progressPanel1.Parent;
                    progressPanel1.Location =
                        new Point(parent.Bounds.X + parent.Bounds.Width / 2 - progressPanel1.Width / 2,
                                  parent.Bounds.Y + parent.Bounds.Height / 2 - progressPanel1.Height / 2);
                    progressPanel1.Visible = true;
                    string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
                                                   importFile.FileName +
                                                   ";Extended Properties=Excel 12.0;Persist Security Info=False";
                    excelConnection = new OleDbConnection(excelConnectionString);
                    OleDbCommand cmd =
                        new OleDbCommand("Select [ProductID],[ProductName],[EnglishName],[VietName],[JapanName],[Size]" +
                                         ",[MakerID],[ProductGroupID],[SupplierID],[KindID],[UnitID],[Price],[CurrencyID],[PurposeID] from [Sheet1$]",
                            excelConnection);
                    excelConnection.Open();
                    OleDbDataReader dReader;
                    dReader = cmd.ExecuteReader();
                    int i = 0;
                    int line = 1;

                    string ProductID = string.Empty;
                    string ProductName = string.Empty;
                    string EnglishName = string.Empty;
                    string VietName = string.Empty;
                    string JapanName = string.Empty;
                    string Size = string.Empty;
                    string MakerID = string.Empty;
                    string ProductGroupID = string.Empty;
                    string SupplierID = string.Empty;
                    string KindID = string.Empty;
                    string UnitID = string.Empty;
                    string Price = string.Empty;
                    string CurrencyID = string.Empty;
                    string PurposeID = string.Empty;

                    myConnection.Open();
                    while (dReader.Read())
                    {
                        bool exist = false;
                        line++;

                        //check null
                        try
                        {
                            if (dReader["ProductID"].ToString().Trim().Equals(string.Empty)
                                && dReader["ProductName"].ToString().Trim().Equals(string.Empty)
                                && dReader["EnglishName"].ToString().Trim().Equals(string.Empty)
                                && dReader["VietName"].ToString().Trim().Equals(string.Empty)
                                && dReader["JapanName"].ToString().Trim().Equals(string.Empty)
                                && dReader["Size"].ToString().Trim().Equals(string.Empty)
                                && dReader["MakerID"].ToString().Trim().Equals(string.Empty)
                                && dReader["ProductGroupID"].ToString().Trim().Equals(string.Empty)
                                && dReader["SupplierID"].ToString().Trim().Equals(string.Empty)
                                && dReader["KindID"].ToString().Trim().Equals(string.Empty)
                                && dReader["UnitID"].ToString().Trim().Equals(string.Empty)
                                && dReader["Price"].ToString().Trim().Equals(string.Empty)
                                && dReader["CurrencyID"].ToString().Trim().Equals(string.Empty)
                                && dReader["PurposeID"].ToString().Trim().Equals(string.Empty)
                                )
                            {
                                countErr++;
                                listErr.Add(new Utilities.ListItem(line.ToString(), dReader["ProductID"].ToString(), "Null line"));
                                exist = true;
                            }
                        }
                        catch (Exception e)
                        {
                            countErr++;
                            listErr.Add(new Utilities.ListItem(line.ToString(), dReader["ProductID"].ToString(), e.Message));
                            exist = true;
                        }

                        //check valid data
                        if (!exist)
                        {
                            try
                            {
                                ProductID = (dReader["ProductID"].ToString().Trim().Equals(string.Empty))
                                             ? "null"
                                             : "N'" + dReader["ProductID"].ToString().Trim() + "'";
                                ProductName = (dReader["ProductName"].ToString().Trim().Equals(string.Empty))
                                                ? "null"
                                                : "N'" + dReader["ProductName"].ToString().Trim() + "'";
                                EnglishName = (dReader["EnglishName"].ToString().Trim().Equals(string.Empty))
                                               ? "null"
                                               : "N'" + dReader["EnglishName"].ToString().Trim() + "'";
                                VietName = (dReader["VietName"].ToString().Trim().Equals(string.Empty))
                                                 ? "null"
                                                 : "N'" + dReader["VietName"].ToString().Trim() + "'";
                                JapanName = (dReader["JapanName"].ToString().Trim().Equals(string.Empty))
                                            ? "null"
                                            : "N'" + dReader["JapanName"].ToString().Trim() + "'";
                                Size = (dReader["Size"].ToString().Trim().Equals(string.Empty))
                                             ? "null"
                                             : "N'" + dReader["Size"].ToString().Trim() + "'";
                                MakerID = (dReader["MakerID"].ToString().Trim().Equals(string.Empty))
                                                ? "null"
                                                : "N'" + dReader["MakerID"].ToString().Trim() + "'";
                                ProductGroupID = (dReader["ProductGroupID"].ToString().Trim().Equals(string.Empty))
                                               ? "null"
                                               : "N'" + dReader["ProductGroupID"].ToString().Trim() + "'";
                                SupplierID = (dReader["SupplierID"].ToString().Trim().Equals(string.Empty))
                                                 ? "null"
                                                 : "N'" + dReader["SupplierID"].ToString().Trim() + "'";
                                KindID = (dReader["KindID"].ToString().Trim().Equals(string.Empty))
                                            ? "null"
                                            : "N'" + dReader["KindID"].ToString().Trim() + "'";
                                UnitID = (dReader["UnitID"].ToString().Trim().Equals(string.Empty))
                                                ? "null"
                                                : "N'" + dReader["UnitID"].ToString().Trim() + "'";
                                Price = (dReader["Price"].ToString().Trim().Equals(string.Empty))
                                               ? "null"
                                               : dReader["Price"].ToString().Trim();
                                CurrencyID = (dReader["CurrencyID"].ToString().Trim().Equals(string.Empty))
                                                 ? "null"
                                                 : "'" + dReader["CurrencyID"].ToString().Trim() + "'";
                                PurposeID = (dReader["PurposeID"].ToString().Trim().Equals(string.Empty))
                                            ? "null"
                                            : "N'" + dReader["PurposeID"].ToString().Trim() + "'";

                            }
                            catch (Exception ex)
                            {
                                exist = true;
                                listErr.Add(new Utilities.ListItem(line.ToString(),
                                                                   dReader["ProductID"].ToString(),
                                                                   ex.Message));
                            }
                        }

                        //check duplicate
                        if (!exist)
                        {
                            try
                            {
                                SqlCommand cmd_sql = myConnection.CreateCommand();
                                cmd_sql.CommandText = "SELECT * FROM [243_Product] WHERE [ProductID]=N'" +
                                                      dReader["ProductID"].ToString() + "'";
                                SqlDataReader dataReader = cmd_sql.ExecuteReader();
                                if (dataReader.Read())
                                {

                                    exist = true;
                                    countDup++;
                                    listDup.Add(new Utilities.ListItem(line.ToString(), dReader["ProductID"].ToString(), "Duplicate"));
                                }
                                dataReader.Close();
                                cmd_sql.Dispose();
                            }
                            catch (Exception e)
                            {
                                exist = true;
                                listDup.Add(new Utilities.ListItem(line.ToString(), dReader["ProductID"].ToString(), e.Message));
                            }
                        }

                        //Insert to database
                        if (!exist)
                        {
                            try
                            {
                                string sql = "INSERT INTO [243_Product] ("
                                         + "[ProductID],[ProductName],[EnglishName],[VietName],[JapanName],[Size],[MakerID]," +
                                             "[ProductGroupID],[SupplierID],[KindID],[UnitID],[Price],[CurrencyID],[PurposeID] )"
                                         + " VALUES (" + ProductID + ", " + ProductName + ", " + EnglishName + ","
                                         + VietName + "," + JapanName + "," + Size + "," + MakerID + "," + ProductGroupID + "," + SupplierID + ","
                                         + KindID + "," + UnitID + "," + Price + "," + CurrencyID + "," + PurposeID + ")";
                                SqlCommand cmd_sql = new SqlCommand(sql, myConnection);

                                cmd_sql.ExecuteNonQuery();
                                cmd_sql.Dispose();
                                countOk++;

                                //write Log
                                log.Table = LogConstant.Table.F2Order.Product;
                                log.Task = LogConstant.Task.Import;
                                log.Description = "ProductID: " + ProductID + "; ProductName: " + ProductName;
                                log.WriteLog();

                            }
                            catch (Exception ex)
                            {
                                listErr.Add(new Utilities.ListItem(line.ToString(), dReader["ProductID"].ToString(), ex.Message));
                            }

                        }
                    }
                    myConnection.Close();
                    progressPanel1.Visible = false;
                    excelConnection.Close();
                    //MessageBox.Show(i + " records have been imported. \n" + countDup.ToString() + " record(s) duplicated (Lines: " + lineDup + ")\nLines have error OptionID: " + lineNo);
                    //LoadData();
                    Frm_ImportReport report = new Frm_ImportReport(countOk, listDup, listErr, "PartList", "PartNo");
                    report.StartPosition = FormStartPosition.CenterScreen;
                    report.Show();
                    report.Activate();
                }
                catch (Exception ex)
                {
                    if (excelConnection.State == ConnectionState.Open)
                    {
                        excelConnection.Close();
                    }
                    if (myConnection.State == ConnectionState.Open)
                    {
                        myConnection.Close();
                    }
                    progressPanel1.Visible = false;
                    MessageBox.Show(ex.Message);
                }

            }
        }

        protected virtual void InitPopupMenu()
        {
            menu = new DXPopupMenu();
            menu.Items.Add(new DXMenuItem("Export all", new EventHandler(OnItemClickExportAll), null, null, null, null));
            menu.Items.Add(new DXMenuItem("Export selected row(s)", new EventHandler(OnItemClickExportRows), null, null, null, null));

        }
        void OnItemClickExportAll(object sender, EventArgs e)
        {
            Utilities.ExportToExcel(gridView1, 1, true);
        }
        void OnItemClickExportRows(object sender, EventArgs e)
        {
            Utilities.ExportToExcel(gridView1, 0, true);
        }

        #endregion

        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            GridView view = sender as GridView;


            //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert
            if (view.IsNewItemRow(e.RowHandle))
            {
                //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại

            }
            //Cũ thì update
            else
            {
                string ProductID = (view.GetRowCellValue(e.RowHandle, view.Columns["ProductID"]).ToString() == "")
                                   ? "null"
                                   : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["ProductID"]).ToString() + "'";

                string ProductName = (view.GetRowCellValue(e.RowHandle, view.Columns["ProductName"]).ToString() == "")
                                     ? "null"
                                     : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["ProductName"]).ToString() +
                                       "'";

                string EnglishName = (view.GetRowCellValue(e.RowHandle, view.Columns["EnglishName"]).ToString() == "")
                                       ? "null"
                                       : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["EnglishName"]).ToString() +
                                         "'";

                string VietName = (view.GetRowCellValue(e.RowHandle, view.Columns["VietName"]).ToString() == "")
                                  ? "null"
                                  : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["VietName"]).ToString() + "'";

                string JapanName = (view.GetRowCellValue(e.RowHandle, view.Columns["JapanName"]).ToString() == "")
                                      ? "null"
                                      : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["JapanName"]).ToString() +
                                        "'";

                string Size = (view.GetRowCellValue(e.RowHandle, view.Columns["Size"]).ToString() == "")
                                    ? "null"
                                    : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["Size"]).ToString() + "'";

                string MakerID = (view.GetRowCellValue(e.RowHandle, view.Columns["MakerID"]).ToString() == "")
                                  ? "null"
                                  : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["MakerID"]).ToString() + "'";

                string ProductGroupID = (view.GetRowCellValue(e.RowHandle, view.Columns["ProductGroupID"]).ToString() == "")
                                   ? "null"
                                   : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["ProductGroupID"]).ToString() + "'";

                string SupplierID = (view.GetRowCellValue(e.RowHandle, view.Columns["SupplierID"]).ToString() == "")
                                   ? "null"
                                   : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["SupplierID"]).ToString() + "'";

                string KindID = (view.GetRowCellValue(e.RowHandle, view.Columns["KindID"]).ToString() == "")
                                     ? "null"
                                     : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["KindID"]).ToString() + "'";

                string UnitID = (view.GetRowCellValue(e.RowHandle, view.Columns["UnitID"]).ToString() == "")
                                       ? "null"
                                       : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["UnitID"]).ToString() + "'";

                string Price = (view.GetRowCellValue(e.RowHandle, view.Columns["Price"]).ToString() == "")
                                   ? "null"
                                   : view.GetRowCellValue(e.RowHandle, view.Columns["Price"]).ToString();

                string CurrencyID = (view.GetRowCellValue(e.RowHandle, view.Columns["CurrencyID"]).ToString() == "")
                                   ? "null"
                                   : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["CurrencyID"]).ToString() + "'";

                string PurposeID = (view.GetRowCellValue(e.RowHandle, view.Columns["PurposeID"]).ToString() == "")
                                  ? "null"
                                  : "N'" + view.GetRowCellValue(e.RowHandle, view.Columns["PurposeID"]).ToString() + "'";

                string id = (view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString() == "")
                                ? "null"
                                : view.GetRowCellValue(e.RowHandle, view.Columns["ID"]).ToString();

                string update = "update [243_Product] set [ProductID]=" + ProductID
                                + ", [ProductName] = " + ProductName
                                + ", [EnglishName] = " + EnglishName
                                + ", [VietName] = " + VietName
                                + ", [JapanName] = " + JapanName
                                + ", [Size] = " + Size
                                + ", [MakerID] = " + MakerID
                                + ", [ProductGroupID] = " + ProductGroupID
                                + ", [SupplierID] = " + SupplierID
                                + ", [KindID] = " + KindID
                                + ", [UnitID] = " + UnitID
                                + ", [Price] = " + Price
                                + ", [CurrencyID] = " + CurrencyID
                                + ", [PurposeID] = " + PurposeID
                                + " where [ID] = " + id;
                if (BaseDAO.ExecuteNonQuery(update) > 0)
                {

                    //write Log
                    log.Table = LogConstant.Table.F2Order.Product;
                    log.Task = LogConstant.Task.Update;
                    log.Description = "ProductID: " + ProductID + "; ProductName: " + ProductName;
                    log.WriteLog();

                }
            }

        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt)
            {
                if (e.KeyCode == Keys.E)
                {
                    if (gridView1.OptionsBehavior.Editable)
                    {
                        //gridView1.fo;
                        gridView1.OptionsBehavior.Editable = false;
                    }
                    else
                    {
                        gridView1.OptionsBehavior.Editable = true;
                        gridView1.Columns["ID"].OptionsColumn.AllowEdit = false;
                    }
                }
            }
        }
    }
}
